//
//  QCSettingCell.swift
//  爱汽车
//
//  Created by liujianlong on 2023/8/23.
//

import UIKit
enum QCSettingCellType{
    case normal
    case onlyText(_ subText:String)
    case subImg(_ imgname:String)
    case switchBtn(_ ison:Bool)
}
class QCSettingCell: UITableViewCell {
    @IBOutlet var img: UIImageView!
    @IBOutlet var subImg: UIImageView!
    @IBOutlet var title: UILabel!
    @IBOutlet var subTitle: UILabel!
    @IBOutlet var switchBtn: UISwitch!
    @IBOutlet var line: UIView!
    @IBOutlet var subTitleRight: NSLayoutConstraint!
    @IBOutlet var titleLeft: NSLayoutConstraint!
    var block:((_ ison:Bool)->Void)?
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }
    
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
    }
    
    @IBAction func actionForSwitch(_ sender: UISwitch) {
        block?(sender.isOn)
    }
    var type:QCSettingCellType = .normal{
        didSet{
            switch type{
            case .normal:
                img.isHidden = false
                switchBtn.isHidden = true
                subTitle.isHidden = false
                subImg.isHidden = false
                contentView.bgHexColor = "#161718"
                subImg.image = UIImage(named:"箭头_右")
                titleLeft.constant = 10
            case let .onlyText(subText):
                img.isHidden = true
                switchBtn.isHidden = true
                subTitle.isHidden = false
                subImg.isHidden = subText.count > 0
                contentView.bgHexColor = "#1F2022"
                subImg.image = UIImage(named:"箭头_右")
                subTitle.text = subText
                titleLeft.constant = -34
                subTitleRight.constant = subText.count > 0 ? 20 : -5
            case let .subImg(imgname):
                img.isHidden = true
                switchBtn.isHidden = true
                subTitle.isHidden = true
                subImg.isHidden = false
                contentView.bgHexColor = "#1F2022"
                subImg.image = UIImage(named: imgname)
                titleLeft.constant = -34
                subTitleRight.constant = -5
                //print("=========  \(title.text)  = \(imgname)")
            case let .switchBtn(ison):
                img.isHidden = true
                switchBtn.isHidden = false
                subTitle.isHidden = true
                subImg.isHidden = true
                switchBtn.isOn = ison
                contentView.bgHexColor = "#1F2022"
                titleLeft.constant = -34
                subTitleRight.constant = -5
            }
        }
    }
    
}
